package com.kaifamiao.tags;

import javax.servlet.jsp.JspContext;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import java.io.IOException;

public class ForTag extends SimpleTagSupport {

    // 声明三个字段用来接受页面标签中相应属性的值
    private Integer begin ;
    private Integer step ;
    private Integer end ;

    @Override
    public void doTag() throws JspException, IOException {
        JspContext ctx = this.getJspContext();
        JspWriter out = ctx.getOut();

        if( step == null ) {
            step = 1 ;
        }

        for ( int i = begin , count = 1 ; i <= end ; i += step , count++ ) {
            out.println( "<p style='text-align:center;border:1px solid blue;'>");
            out.println( "第" + count + "次循环" );
            out.println( "</p>");
        }

    }

    public Integer getBegin() {
        return begin;
    }

    public void setBegin(Integer begin) {
        System.out.println( "setBegin" );
        this.begin = begin;
    }

    public Integer getStep() {
        return step;
    }

    public void setStep(Integer step) {
        this.step = step;
    }

    public Integer getEnd() {
        return end;
    }

    public void setEnd(Integer end) {
        this.end = end;
    }
}
